package logger

import (
	"go.uber.org/zap"
	"strconv"
	"strings"
	"wms/define"
)

func getSubMenusName(data []*define.MenuReply) []string {
	names := make([]string, 0)
	for _, v := range data {
		if v.Name != "" {
			names = append(names, v.Name)
		}
		if v.SubMenus != nil {
			names = append(names, getSubMenusName(v.SubMenus)...)
		}
	}
	return names
}

func LogGetMenusName(data []*define.MenuReply) {
	names := getSubMenusName(data)
	zap.L().Info(strings.Join(names, ", "))
}

func LogGetRolesInfo(data []*define.RoleListReply) {
	infos := make([]string, 0)
	for _, v := range data {
		single := "[" + v.Name + ", " + v.Identity + ", " + strconv.FormatInt(int64(v.IsAdmin), 10) + "]"
		infos = append(infos, single)
	}
	zap.L().Info(strings.Join(infos, ", "))
}
